using System;
using Taimila.Entify;
using Taimila.Entify.Attributes;

namespace Taimila.Entify.UnitTests
{
	[Entity(Version = 1.0)]
	public class ParentTestEntity : Entity
	{
		[EntityProperty(PersistentName = "TextProperty")]
		public string Text
		{
			get;
			set;
		}
		
		private ChildTestEntity child;
		private long? childLazyLoadIdentifier;
		
		[EntityProperty(PersistentName = "Child", Relationship = true)]
		public ChildTestEntity Child
		{
			get
			{
				if(this.childLazyLoadIdentifier == null)
				{
					return null;	
				}
				else if(this.child == null)
				{
					this.child = this.LazyLoadEntity<ChildTestEntity>(this.childLazyLoadIdentifier);
					return this.child;
				}
				else
				{
					return this.child;	
				}
			}
			set
			{
				if(value == null)
				{
					this.childLazyLoadIdentifier = null;
					this.child = null;
				}
				else
				{
					this.childLazyLoadIdentifier = value.GetEntityId();
					this.child = value;
				}
			}
		}
	}
}
